package com.ruoyi.teach.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.teach.domain.NbKnowledgePointsVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.teach.domain.NbKnowledgePoints;
import com.ruoyi.teach.service.INbKnowledgePointsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 知识点Controller
 * 
 * @author ruoyi
 * @date 2021-12-08
 */
@RestController
@RequestMapping("/teach/knowledge_points")
public class NbKnowledgePointsController extends BaseController
{
    @Autowired
    private INbKnowledgePointsService nbKnowledgePointsService;

    /**
     * 查询知识点列表
     */
    @PreAuthorize("@ss.hasPermi('teach:knowledge_points:list')")
    @GetMapping("/list")
    public TableDataInfo list(NbKnowledgePoints nbKnowledgePoints)
    {
        startPage();
        List<NbKnowledgePoints> list = nbKnowledgePointsService.selectNbKnowledgePointsList(nbKnowledgePoints);
        return getDataTable(list);
    }
    /**
     * 查询知识点列表
     */
    @PreAuthorize("@ss.hasPermi('teach:knowledge_points:list')")
    @GetMapping("/tree")
    public AjaxResult tree(NbKnowledgePoints nbKnowledgePoints)
    {
        List<NbKnowledgePoints> list = nbKnowledgePointsService.selectNbKnowledgePointsTree(nbKnowledgePoints);
        return AjaxResult.success(list);
    }

    /**
     * 导出知识点列表
     */
    @PreAuthorize("@ss.hasPermi('teach:knowledge_points:export')")
    @Log(title = "知识点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NbKnowledgePoints nbKnowledgePoints)
    {
        List<NbKnowledgePoints> list = nbKnowledgePointsService.selectNbKnowledgePointsList(nbKnowledgePoints);
        ExcelUtil<NbKnowledgePoints> util = new ExcelUtil<NbKnowledgePoints>(NbKnowledgePoints.class);
        util.exportExcel(response, list, "知识点数据");
    }

    /**
     * 获取知识点详细信息
     */
    @PreAuthorize("@ss.hasPermi('teach:knowledge_points:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(nbKnowledgePointsService.selectNbKnowledgePointsById(id));
    }

    /**
     * 新增知识点
     */
    @PreAuthorize("@ss.hasPermi('teach:knowledge_points:add')")
    @Log(title = "知识点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NbKnowledgePoints nbKnowledgePoints)
    {
        return toAjax(nbKnowledgePointsService.insertNbKnowledgePoints(nbKnowledgePoints));
    }

    /**
     * 修改知识点
     */
    @PreAuthorize("@ss.hasPermi('teach:knowledge_points:edit')")
    @Log(title = "知识点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NbKnowledgePoints nbKnowledgePoints)
    {
        return toAjax(nbKnowledgePointsService.updateNbKnowledgePoints(nbKnowledgePoints));
    }

    /**
     * 删除知识点
     */
    @PreAuthorize("@ss.hasPermi('teach:knowledge_points:remove')")
    @Log(title = "知识点", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(nbKnowledgePointsService.deleteNbKnowledgePointsByIds(ids));
    }
}
